<template>
  <j-modal title="谈话录入" :width="1100" :visible="visible" switchFullscreen :maskClosable="false"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }" @cancel="handleCancel" :destroyOnClose="true"
    :footer="null">
    <a-spin :spinning="confirmLoading">
      <div class="con-content">
        <div class="con-content-top">
          <a-steps :current="current" size="small">
            <a-step v-for="item in steps" :key="item.title" :title="item.title" />
          </a-steps>
        </div>
        <div class="content-form">
          <BaseInformation v-show="current === 0" ref="baseInformationId" :isOverdue="isOverdue" />
          <TalkInformation v-show="current === 1" ref="talkInformationId" />
          <div class="footerBox">
            <a-button class="btn" @click="handleCancel">
              取消
            </a-button>
            <a-button v-if="current > 0" style="margin-left: 8px" @click="prev">
              上一步
            </a-button>
            <a-button v-if="current < steps.length - 1" style="margin-left: 8px" type="primary" @click="next">
              下一步
            </a-button>
            <!-- <a-popconfirm title="确定发起审批？" ok-text="是" cancel-text="否" @confirm="submitHandler()"> -->
            <a-button type="primary" @click="submitHandler" style="margin-left:8px;" v-if="current === 1"
              :loading="submitLoading">
              提交
            </a-button>
            <!-- </a-popconfirm> -->
          </div>
        </div>
      </div>
    </a-spin>
  </j-modal>
</template>

<script>
import * as interviewApi from '@/api/sjsk/help/interview.js'
import BaseInformation from './BaseInformation'
import TalkInformation from './TalkInformation'
export default {
  name: 'addInterviewModal',
  components: { BaseInformation, TalkInformation },
  data() {
    return {
      width: 1000,
      visible: false,
      disableSubmit: false,
      confirmLoading: false,
      current: 0,
      steps: [
        {
          title: '基本资料'
        },
        {
          title: '谈话内容'
        },
      ],
      isHaveTarget: true,
      submitLoading: false,
      // formData: {},
      id: "",
      status: "",
      isOverdue: false,
      detailData: {},
      category: 1 //案事件
    }
  },
  methods: {
    show(type, record) {
      this.visible = true
      this.current = 0
      this.id = record.id
      this.status = record.status
      if (record.status == 5) { //已逾期
        this.isOverdue = true
      } else {
        this.isOverdue = false
      }
      this.getBookDetail(record.id) //读详情回填信息
    },
    getBookDetail(id) {
      interviewApi.interviewRecordDetail(id).then((res) => {
        if (res.success) {
          this.$refs.baseInformationId.setData(res.result)
          this.detailData = res.result
        } else {
          this.$message.success(res.message)
        }
      })
        .catch((e) => {
          this.$message.warning(res.message)
        })
    },
    handleCancel() {
      this.visible = false
    },
    next() {
      // 第一页
      if (this.current == 0) {
        let flag = this.$refs.baseInformationId.onValidate()
        if (!flag) {
          return
        }
        if (this.status == 2) { //已经预约，待录入,读取预约详情回填信息
          this.$refs.talkInformationId.setData(this.detailData) //填充下一页信息
        }
        this.$refs.talkInformationId.getTypeData()
      }
      this.current++
    },
    prev() {
      this.current--
    },
    submitHandler() {
      let flag = this.$refs.talkInformationId.onValidate()
      if (!flag) {
        return
      }
      let baseData = this.$refs.baseInformationId.getData()
      let talkData = this.$refs.talkInformationId.getData()
      if (talkData != undefined) {
        let params = Object.assign(baseData, talkData, { id: this.id, status: this.status })
        console.log('params')
        console.log(params)
        this.submitLoading = true
        interviewApi.inputInterviewRecord(params).then(res => {
          if (res.success) {
            this.visible = false
            this.submitLoading = false
            this.$message.success(res.message)
            this.$emit('ok')
          } else {
            this.submitLoading = false
            this.$message.warning(res.message)
          }
        })
          .catch(() => {
            this.submitLoading = false
            this.$message.error(res.message)
          })
      }
    }
  }
}
</script>
<style lang="less" scoped>
.con-content {
  .con-content-top {
    width: 60%;
    margin: 10px auto 50px auto;
  }

  // padding-bottom: 50px;
}

.footerBox {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  padding-top: 20px;
  border-top: 1px solid #ccc;
}
</style>
